﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace SacMauVN
{
    public partial class ChiTietSanPham : System.Web.UI.Page
    {
        private static int pID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["pID"] != null)
            {
                pID = Convert.ToInt32(Request.QueryString["pID"]);
                LoadSanPham(pID);
            }
        }

        private void LoadSanPham(int pID)
        {
            string sql = "SELECT * FROM tblSMVNSanPham WHERE ID = @ID";
            List<SqlParameter> arrParams = new List<SqlParameter>();
            arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, pID));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParams);
            rptSanPham.DataSource = dt;
            rptSanPham.DataBind();
            ltrThongTin.Text = dt.Rows[0]["ThongTin"].ToString();
            LoadSanPhamTuongDuong(Convert.ToInt32(dt.Rows[0]["Menu_ID"]), Convert.ToInt32(dt.Rows[0]["ID"]));
        }

        private void LoadSanPhamTuongDuong(int MenuID, int SanPhamID)
        {
            string sql = "SELECT TOP 4 * FROM tblSMVNSanPham WHERE Menu_ID = @Menu_ID AND ID <> @ID";
            List<SqlParameter> arrParams = new List<SqlParameter>();
            arrParams.Add(SqlHelper.CreateParameterObject("@Menu_ID", SqlDbType.Int, ParameterDirection.Input, MenuID));
            arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, SanPhamID));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParams);
            rptListSameProduct.DataSource = dt;
            rptListSameProduct.DataBind();
        }
    }
}
